gcapp.set "messageVisible","false"
Words "#sm",1,2,@gcapp.scriptMessage
#boxNum=#sm[1]-1     ! current _BOX index (0 based)
#poiNum=#sm[2]-1     ! insert after current one
gcapp.get doc,frontDocument
doc.get recRef,"keyRecord"
! find _BOX elements in this record, we want #boxNum (0 based)
recRef.findStructures maps,"_BOX"
maps.#boxNum.get boxRef
! find _POI in box element and add after it
boxRef.findStructures pois,"_POI"
doc.beginUndo
if @pois.count=0
  ! first one goes at the end
  #label="Point of Interest 1"
  boxRef.addStructure poiRef,"_POI",#label
else
  ! after #poiNum in pois
  #label="Point of Interest "&(#poiNum+2)
  maps.#boxNum.addStructure poiRef,"_POI",#label,pois.#poiNum
endif
doc.endUndo local("Add Point of Interest")
